#include "StdAfx.h"
#include "Logger.h"

Logger* Logger::m_Singeton = NULL;

Logger::Logger()
{
	m_Teller.Start();
	m_File.open(_T("./Game.log"));
	if(!m_File)
		MessageBox(NULL, _T("ERROR: Kan geen log bestand maken. Logging disabled"), NULL, MB_OK);
	else
	{
		SYSTEMTIME nu;
		GetSystemTime(&nu);
		m_File << m_Teller.GetTimeBig() << _T("\tLog Created on ") << nu.wDay << _T("/") << nu.wMonth << _T("/") << nu.wYear;
		m_File << _T(" ") << nu.wHour << _T(":") << nu.wMinute << _T(":") << nu.wSecond << _T("\n");
	}
}
Logger::~Logger()
{
	m_Teller.Stop();
	m_File << m_Teller.GetTimeBig() << _T("\tEnd Log");
	m_File.close();
}
void Logger::Log(const tstring &text)
{
	m_File << m_Teller.GetTimeBig() << _T("\t") << text << _T("\n");
	OutputDebugString(tstring(text + _T("\n")).c_str());
}

Logger* Logger::GetSingleton()
{
	if(m_Singeton == NULL)
		m_Singeton = new Logger();
	return m_Singeton;
}